import { getUserInfo, getScoreInfo } from "../services/api-user";

export default {
    namespace: 'users',
    state: {
        cityList: {},
        scoreInfo: {},
    },

    effects: {
        *fetchUserInfo({ payload, cb }, { call, put }) {
            const response = yield call(getUserInfo, payload)
            if (response.statusCode === 200) {
                yield put({
                    type: 'updateUserInfo',
                    payload: response.data || {},
                })
            }
            if (cb) cb(response)
        },
        *fetchScoreInfo({ payload, cb }, { call, put }) {
            const response = yield call(getScoreInfo, payload)
            if (response.statusCode === 200) {
                yield put({
                    type: 'updateScoreInfo',
                    payload: response.data || {},
                })
            }
            if (cb) cb(response)
        },
    },

    reducers: {
        updateUserInfo(state, { payload }) {
            return {
                ...state,
                cityList: { ...payload },
            }
        },
        updateScoreInfo(state, { payload }) {
            return {
                ...state,
                scoreInfo: { ...payload },
            }
        },
    },
};